//
//  BaseVisitorView.swift
//  SinaMicroBlog
//
//  Created by xinjuwen on 15/10/19.
//  Copyright © 2015年 xinjuwen. All rights reserved.
//

import UIKit
import SnapKit

 class BaseVisitorView: UIView {
    
    //访客页面图标
    lazy var iconImageView: UIImageView = UIImageView()
    
    //访客页面小房子图标
    lazy var homeImageView: UIImageView = {
        
        //创建一个临时label
        var temImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
        
        //默认是隐藏的
        temImageView.hidden = true
        
        return temImageView
        
    }()
    
    //访客页面文字
    lazy var message: UILabel = {
        
        return UILabel(textColor: UIColor.lightGrayColor(), fontSize: 14)
        
    }()
    
    
    //注册按钮单击事件
    func registerBtnClick() {
        print("register")
    }
    
    
    //登陆按钮单击事件
    func loginBtnClick() {
        print("login")
    }
    
    
    //访客页面注册按钮
    lazy var registerBtn: UIButton = {
        
        //创建一个临时按钮
        var tempBtn = UIButton(title: "注 册", titleColor: UIColor.orangeColor(), backgroundImage: "common_button_white_disable")
        
        //添加单击事件
        tempBtn.addTarget(self, action: "registerBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return tempBtn
    }()
    
    
    //访客页面登陆按钮
    lazy var loginBtn: UIButton = {
        
        let tempBtn = UIButton(title: "登 陆", titleColor: UIColor.darkGrayColor(), backgroundImage: "common_button_white_disable")
        
        //添加单击事件
        tempBtn.addTarget(self, action: "loginBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return tempBtn
        }()

    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor(white: CGFloat(0.94), alpha: 1)
        
        //添加UI控件
        setupUI()
    }
    

    /**
    往访客页面添加控件
    */
    func setupUI() {
        
        //添加访客页面图标
        addSubview(iconImageView)
        
        //添加小房子图标
        addSubview(homeImageView)
        
        //添加访客页面文字
        addSubview(message)
        
        //添加访客页面注册按钮
        addSubview(registerBtn)
        
        //添加访客页面登陆按钮
        addSubview(loginBtn)
        
        //布局图标
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.width.height.equalTo(160)
            make.center.equalTo(self).offset(CGPointMake(0, -80))
        }
        
        //布局小房子图标
        homeImageView.snp_makeConstraints { (make) -> Void in
            make.width.height.equalTo(90)
            make.center.equalTo(iconImageView)
        }
        
        //布局文字
        message.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(220)
            make.height.equalTo(50)
            make.center.equalTo(self).offset(CGPointMake(0, 50))
        }
        
        //布局注册按钮
        registerBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(message)
            make.right.equalTo(message.snp_centerX).offset(-15)
            make.centerY.equalTo(message.snp_centerY).offset(50)
            make.height.equalTo(35)
        }
        
        //布局登陆按钮
        loginBtn.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(message)
            make.left.equalTo(message.snp_centerX).offset(15)
            make.centerY.equalTo(message.snp_centerY).offset(50)
            make.height.equalTo(35)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
